package com.bytedance.improvingroad.activity

import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.view.ActionMode
import com.bytedance.improvingroad.R
import com.bytedance.improvingroad.databinding.ActivityTopAppBarBinding
import com.bytedance.improvingroad.utils.Utils

class TopAppBarActivity : BaseBindingActivity<ActivityTopAppBarBinding>() {
    override fun initData() {

    }

    override fun initListener() {
        binding.topAppBar.setNavigationOnClickListener {
            Utils.showToast("导航键被点击了")
        }

        binding.topAppBar.setOnMenuItemClickListener { menuItem ->
            when (menuItem.itemId) {
                R.id.search -> {
                    Utils.showToast("search菜单被点击了")
                    true
                }
                R.id.more -> {
                    Utils.showToast("more菜单被点击了")
                    true
                }
                else -> false
            }
        }

        val callback = object : ActionMode.Callback {

            override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
                menuInflater.inflate(R.menu.contextual_action_bar, menu)
                return true
            }

            override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean {
                return false
            }

            override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean {
                return when (item?.itemId) {
                    R.id.share -> {
                        // Handle share icon press
                        true
                    }
                    R.id.delete -> {
                        // Handle delete icon press
                        true
                    }
                    R.id.more -> {
                        // Handle more item (inside overflow menu) press
                        mode?.finish()
                        true
                    }
                    else -> false
                }
            }

            override fun onDestroyActionMode(mode: ActionMode?) {
            }
        }
        val actionMode = startSupportActionMode(callback)
        actionMode?.title = "1 selected"

    }
}